package com.diko.config.exceptionhandler;


import com.diko.commonUtils.R;
import com.diko.commonUtils.exceptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Emma Li
 * @date 2020/9/13 - 21:43
 */
@ControllerAdvice
@Slf4j
public class globalExceptionHandler {
    /*全局变量*/
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();

        return R.error().message("执行了全局异常处理..");

    }

    /*自定义变量*/
    @ExceptionHandler(myException.class)
    @ResponseBody
    public R error(myException e){
        log.error(exceptionUtil.getMessage(e));//把错误信息放到日志里
        e.printStackTrace();
        return R.error().message(e.getMsg()).code(e.getCode());
    }


}
